import { ref, watch, reactive, getCurrentInstance, computed } from "vue"
import cellStatus from './component/cellStatus'
import cellPayFlag from './component/cellPayFlag'
import cellButton from './component/cellButton'
import request from '@/utils/request'
import { download } from '@/utils/request'
import $button from '@/button'
function batchListApi(dataRequest) {
    return request({
        url: '/student/batch/page',
        method: 'POST',
        data: dataRequest
    })
}


// 缴费
export const paymentApi = (dataRequest) => {
    return request({
        url: '/student/batch/pay/batch',
        method: 'POST',
        data: dataRequest
    })
}
//
export const listAllListApi = (dataRequest) => {
    return request({
        url: '/system/user/listAll',
        method: 'POST',
        data: dataRequest
    })
}
// 删除
export const batchDelApi = (dataRequest) => {
    return request({
        url: '/student/batch/delete',
        method: 'POST',
        data: dataRequest,
    })
}
//导出
function exportApi(dataRequest) {
    return request({
        url: '',
        method: 'POST',
        data: dataRequest
    })
}
export const tableItem = reactive({
    tree: true,//树形
    select: false,
    loading:false,
    expandAll: true,//树形默认展开
    align: 'center',//对齐方式 全局
    column: [
        {
            label: '批次号',
            prop: 'batchNum',
        },
        {
            label: '所属机构',
            prop: 'nickName',
        },
        {
            label: '学员数量',
            prop: 'studentNum',
        },
        {
            label: '导入时间',
            prop: 'importDate',
        },

        {
            label: '缴费日期',
            prop: 'payDate',
        },
        {
            label: '是否已缴费',
            component: cellPayFlag
        },
        {
            label: '审核状态',
            prop: 'status',
            component: cellStatus

        },
        {
            label: '操作',
            prop: 'action',
            component: cellButton,
            width: 180
        },
    ],
    pageInfo: {
        request: {
            "batchNum": "", //批次号
            status: '',
            "insId": "", //机构id
            "nickName": "", //机构名称
            "payFlag": "", //缴费状态 1已缴费 0未缴费
            "createDateStart": "", //查询开始时间
            "createDateEnd": "", //查询结束时间
            "createTimeStart": computed( () => {
                if (tableItem.pageInfo.request.createDateStart) {
                    return tableItem.pageInfo.request.createDateStart + "T00:00:00"
                } else {
                    return ""
                }
            }),
            "createTimeEnd":computed( () => {
                if (tableItem.pageInfo.request.createDateEnd) {
                    return tableItem.pageInfo.request.createDateEnd + "T23:59:59"
                } else {
                    return ""
                }
            }),
            "pageDomain": {
                "pageNum": 1,//分页页面数 必须为数字
                "pageSize": 10,//分页页面数据大小  必须为数字
                "orderByColumn": "",//搜索参数
                "isAsc": "",//搜索参数
                "reasonable": ""//搜索参数
            }
        },
        url: '',
        // 分页函数paging
        paging: function () {
            batchListApi(tableItem.pageInfo.request).then(res => {
                tableItem.tableData.data = res.rows
                tableItem.tableData.total = res.total
                // if (!tableItem.tableData.data && tableItem.tableData.data.length == 0) { return }
                tableItem.loading=false
            }).catch(()=>{ tableItem.loading=false});
        }
    },
    // 分页数据 自定义分页函数paging时需要把值赋给tableData
    tableData: {
        total: '',//分页总计
        // 分页数据
        data: []
    },
    moreBtnArray: [],
    // 操作栏按钮
    btnArray: [
        {
            type: 'primary',//类别 摈弃了text
            label: '查看',
            plain: true,//镂空按钮  优先文字按钮
            text: true,//文字按钮
            show: true,
            // 按钮方法
            handle: function (row) {
                console.log('row', row)
            }
        },
        {
            label: '修改',
            type: 'primary',
            show: true,
            text: true,
            handle: function (row) {
                console.log('row', row)
            }
        },
        {
            label: '缴费',
            type: 'primary',
            show: true,
            text: true,
            handle: function (row) {
                console.log('row', row)
            }
        },
        {
            label: '审核',
            type: 'primary',
            show: true,
            text: true,
            handle: function (row) {
                console.log('row', row)
            }
        },
        {
            label: '导出',
            type: 'primary',
            show: true,
            text: true,
            handle: function (row) {
                let downName = row.nickName || ''
                downName = downName + '学员名单'
                download('/student/batch/export', { id: row.id }, downName)
            }
        },
        {
            label: '删除',
            type: 'danger',
            show: true,
            text: true,
            handle: function (row) {
                // proxy.$modal.confirm("确定删除" + row.nickName || '').then(() => {
                //     courseDelApi(row.id).then(res => {
                //         ElMessage.success('操作成功'); tableItem.pageInfo.paging()
                //     })
                // })
            }
        },
    ],
    // 选择框触发
    selectChange: function (row) {
        console.log(row)
    },
}
)



